
<template>
  <div class="wrapp">
    <div class="head">
      <div class="title">Storj补贴设置</div>
    </div>
    <div class="banner">
      <div class="item">
        <span class="itemTitle">收益下限数量</span>
        <RadioGroup v-model="xiaxian_1">
          <Radio label="无" style="margin-right:20px;"></Radio>
          <Radio label="有"></Radio>
        </RadioGroup>
        <div style="margin-left:50px;">
          <Input style="width:300px;" v-model="xiaxian" v-if="xiaxian_1=='有'" placeholder="以币为单位" />

        </div>
      </div>
      <div class="item">
        <span class="itemTitle">收益上限封顶数量</span>
        <RadioGroup v-model="shangxian_1">
          <Radio label="无" style="margin-right:20px;"></Radio>
          <Radio label="有"></Radio>
        </RadioGroup>

        <div style="margin-left:50px;">
          <Input style="width:300px;" v-model="shangxian" v-if="shangxian_1=='有'" placeholder="以币为单位" />
        </div>
      </div>
      <div class="item">

        <span class="itemTitle">每周期默认补贴数量</span>
        <RadioGroup v-model="moren_1">
          <Radio label="无" style="margin-right:20px;"></Radio>
          <Radio label="有"></Radio>
        </RadioGroup>
        <div style="margin-left:50px;">
          <Input style="width:300px;" v-model="moren" v-if="moren_1=='有'" placeholder="以币为单位" />
        </div>
      </div>
      <div class="foot">
        <Button type="primary" @click="sub">提交</Button>
      </div>
    </div>
  </div>
</template>

<script>
import apis from "../../util/apis.js";
export default {
  name: "setBonus",
  data() {
    return {
      xiaxian_1: "",
      shangxian_1: "",
      moren_1: "",
      xiaxian: "",
      shangxian: "",
      moren: ""
    };
  },
  methods: {
    sub() {
      if(this.xiaxian_1==="无"){
        this.xiaxian=0;
      }
      if(this.shangxian_1==="无"){
        this.shangxian=0;
      }
      if(this.moren_1==="无"){
        this.moren=0;
      }
      if (parseFloat(this.shangxian) < parseFloat(this.xiaxian)) {
        this.$Message.error("收益上限小于下限了,你想上天呐！");
        return;
      }
      this.$Modal.confirm({
        title: "确认提交信息",
        content:
          "<div>收益下限数量：" +
          this.xiaxian +
          "</div>" +
          "<div>请输入收益上线数量:" +
          this.shangxian +
          "</div>" +
          "<div>请输入默认补贴数量:" +
          this.moren,
        onOk: () => {
          let payload = {
            defaultAmount: parseFloat(this.moren),
            lowerAmount: parseFloat(this.xiaxian),
            upperAmount: parseFloat(this.shangxian)
          };

          let token = this.$localStorage.storageGet("TOKEN");
          if (!token) {
            this.$router.push({
              name: "Login"
            });
            return;
          }

          this.$axios({
            method: "post",
            url: apis.SJgolbal,
            headers: {
              "Content-Type": "application/json",
              Authorization: "Bearer " + token
            },
            data: payload
          })
            .then(res => {
              console.log(res);
              if (res.status == 200) {
                this.$Message.info("已设置成功");
                this.$router.push({
                  name: "Bonus"
                });
              } else {
                this.$Message.error(res.data.detail);
              }
            })
            .catch(err => {
              this.$Message.error(err.response.data.message);
            });
        },
        onCancel: () => {
          this.$Message.info("已取消提交");
        }
      });
    },
    getShowData() {
      let token = this.$localStorage.storageGet("TOKEN");
      if (!token) {
        this.$router.push({
          name: "Login"
        });
        return;
      }
      this.$axios({
        method: "get",
        url: apis.SJgetGolbal,
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + token
        }
      })
        .then(res => {
          console.log(res);
          if (res.status == 200) {
            if (res.data.lowerAmount!=0) {
              this.xiaxian = res.data.lowerAmount;
              this.xiaxian_1 = "有";
            }else{
              this.xiaxian = res.data.lowerAmount;
              this.xiaxian_1 = "无";
            }
            if (res.data.upperAmount!=0) {
              this.shangxian = res.data.upperAmount;
              this.shangxian_1 = "有";
            }else{
              this.shangxian = res.data.upperAmount;
              this.shangxian_1 = "无";
            }
            if (res.data.defaultAmount!=0) {
              this.moren = res.data.defaultAmount;
              this.moren_1 = "有";
            }else{
              this.moren = res.data.defaultAmount;
              this.moren_1 = "无";
            }
          } else {
            this.$Message.error(res.data.detail);
          }
        })
        .catch(err => {
          // console.log(err);
          this.$Message.error(err.response.data.message);
        });
    }
  },
  created() {},
  mounted() {
    this.getShowData();
  }
};
</script>
<style scoped>
.wrapp {
  padding: 0 20px;
}
.head {
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
  padding: 10px 5px;
  display: flex;
  justify-content: space-between;
}
.banner {
  margin-top: 20px;
}
.title {
  color: #666;
  font-size: 24px;
}
.item {
  margin-top: 15px;
  display: flex;
  line-height: 36px;
}
.itemTitle {
  width: 250px;
  text-align: left;
  margin-right: 20px;
  font-size: 20px;
}
.foot {
  margin-top: 20px;
}
</style>